#include "mainwidget.hpp"
#include "graphic_connector\api\grc_igeometryengine.hpp"
#include "graphic_connector\api\graphic_connector.hpp"
#include "game_controller\headers\game_controller.hpp"

#include "game_model\headers\game_model_distance_unit.hpp"

#include <QMouseEvent>
#include <QLibrary>

#include <math.h>
#include <locale.h>

MainWidget::MainWidget(
	GameController::GameControllerPlugin* _gameController
,	GraphicConnector::GraphicConnectorPlugin* _graphicsController
,	QWidget *parent
)
	:	QGLWidget(parent)
	,	m_gameController( _gameController )
	,	m_graphics( _graphicsController )
{
	// Use QBasicTimer because its faster than QTimer
	timer.start(12, this);
	std::shared_ptr< GameModel::IDistanceUnit > from( new GameModel::DistanceUnit( 0 ) );
	std::shared_ptr< GameModel::IDistanceUnit > to( new GameModel::DistanceUnit( 20 ) );
	m_graphics->getGeometryEngine().setScene( m_gameController->getScene( from, to ) );
	m_graphics->getGeometryEngine().show();
}

MainWidget::~MainWidget()
{
}

void
MainWidget::timerEvent(QTimerEvent *)
{
	updateGraphics();
}

void
MainWidget::updateGraphics()
{
	m_graphics->getGeometryEngine().update();
}